package util

import (
	"crypto/aes"
	"crypto/cipher"
	"fmt"
)

// AesDecryptTsFile 解密AES字节数据
func AesDecryptTsFile(content, key, iv []byte) (resData []byte, err error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}
	blockMode := cipher.NewCBCDecrypter(block, iv)
	if len(content)%blockMode.BlockSize() != 0 {
		return resData, fmt.Errorf("invalid file size: %d", len(content))
	}
	resData = make([]byte, len(content))
	blockMode.CryptBlocks(resData, content)
	return resData, nil
}
